from datetime import datetime
from pathlib import Path
from shutil import copytree

from drek.config import get_directories_of_interest, get_dot_dir  # type: ignore
from drek.utils.environ import get_home_dir  # type: ignore


def get_stamp() -> str:
    now = datetime.now()
    return f"{now.strftime('%Y-%m-%dT%H-%M-%S')}_{int(now.timestamp())}"


def get_destination() -> str:
    return f"{get_home_dir()}/{get_dot_dir()}"


def backup_directories_of_interest(
    dst: str = get_destination(),
    directories_of_interest: list = get_directories_of_interest(),
) -> None:
    stamp = get_stamp()
    if Path(dst).exists():
        for directory in directories_of_interest:
            src = f"{get_home_dir()}/{directory}"
            print(f"{src}:")
            src_path = Path(src)
            if src_path.exists():
                copytree(src, f"{dst}/{stamp}/{directory}")
            else:
                print("Err: src does not exist!")
            print("")
    else:
        print("Err: dst does not exist!")
